package com.platform.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang.StringEscapeUtils;

import java.io.IOException;

public class JsonHtmlSerializer extends JsonSerializer<String> {

    @Override
    public void serialize(String htmlString, JsonGenerator gen, SerializerProvider provider)  throws IOException, JsonProcessingException {
        System.out.println("序列化方法进入");
        String string ="";

        if (!"".equals(htmlString)){
            string =StringEscapeUtils.escapeHtml(htmlString);
        }


        System.out.println(string);
        gen.writeString(string);

}

}